namespace('js.lang');

js.lang.Extends = function(canonicalClassName) {
  this._canonicalClassName = canonicalClassName;
  if (typeof(canonicalClassName) == 'string') {
    this._canonicalClass = this._getClassRefFromCanonicalClassName(canonicalClassName);
  } else {
    this._canonicalClass = canonicalClassName;
  }
  this.$class = new js.lang.Class('js.lang.Extends');
};

js.lang.Extends.prototype = {
  getCanonicalClass: function(imports) {
    if (!this._canonicalClass && imports[this._canonicalClassName]) {
      this._canonicalClass = this._getClassRefFromCanonicalClassName(imports[this._canonicalClassName]);
    }
    return this._canonicalClass;
  },

  _getClassRefFromCanonicalClassName: function(canonicalClassName) {
    var classRef = window;
    var classParts = canonicalClassName.split('.');
    for (var i = 0; i < classParts.length; i++) {
      classRef = classRef[classParts[i]];
    }
    return classRef;
  }
};